package cn.com.callback

import groovy.json.*;
import groovy.swing.impl.DefaultAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import cn.com.elite.EliteBean;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.dataservice.Result;
import java.util.Map;
import java.util.Date;
import java.util.HashMap;
import cn.com.elite.Util;
import cn.com.kh.UcisXML;
import java.net.URLEncoder;

import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;

/**
 *
 * @Title: SwlgAgentStatusDetail
 * @Description:数据分离每天定时插入数据
 * @author: Yuchieh 
 * @date 2021-07-23
 *
 */


public class SwlgWebLoginList implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(SwlgWebLoginList.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response){
				
		response.setCharacterEncoding("UTF-8");
		JSONObject resulterror = new JSONObject();
				

		try{
			//将数据写进his表
			//def todaysql_bak = "INSERT INTO bigdateStaff_his SELECT *,GETDATE() FROM bigdateStaff";
			//eliteBean.update(todaysql_bak, "dataSource");
			//清空表数据
			//def todaysql_del = "TRUNCATE TABLE bigdateStaff";
			//eliteBean.update(todaysql_del, "dataSource");
			//写入数据
			
			//--龙岗话务员登录日志
		    def todaysql_ins17 = "INSERT INTO [sw_lg_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID in('CW0002','LGGLZ1') and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins17, "dataSource");
			
			//--龙华话务员登录日志
		    def todaysql_ins18 = "INSERT INTO [sw_lh_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID in('BASS05','70RGXY') and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins18, "dataSource");
			
			//--宝安话务员登录日志
		    def todaysql_ins19 = "INSERT INTO [sw_ba_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID in('CW0003','BAGLZ1','BASSZ1') and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins19, "dataSource");
			
			//--光明话务员登录日志
		    def todaysql_ins20 = "INSERT INTO [sw_gm_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID in('CW0004','GMGLZU') and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins20, "dataSource");
			
			//--集团话务员登录日志
		    def todaysql_ins21 = "INSERT INTO [sw_jt_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID in('CW0001','GLZ001') and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins21, "dataSource");
			
			//--坪地话务员登录日志
		    def todaysql_ins22 = "INSERT INTO [sw_pd_WebLoginList] ([LOGINKEY],[STAFF_ID],[ROLEGROUP_ID],[LOGINTIME],[STAFFNAME],[AGENT_ID])select LOGINKEY,STAFF_ID,ROLEGROUP_ID,LOGINTIME,STAFFNAME,AGENT_ID from WebLoginList where RoleGroup_ID ='PDSS01' and LOGINTIME<CONVERT(VARCHAR(10),GETDATE(),120) and LOGINTIME>=CONVERT(VARCHAR(10),GETDATE()-1,120)";
			eliteBean.update(todaysql_ins22, "dataSource");

			resulterror.put("code", "1");
			resulterror.put("msg", "数据分离每天定时插入数据写入完成");
			return  resulterror;
			
		}catch(Exception e){
			resulterror.put("code", "-1");
			resulterror.put("msg", "接口异常！"+e);
			return  resulterror;
		}
	}
}